Download the file: http://download.cms.gov/nppes/NPI_Files.html
Remember to use 7zip to unzip it!
Also download: http://sqlitebrowser.org/
In [1]:
import sqlite3
db = "npi_data.db"
In [2]:
conn = sqlite3.connect(db)
c = conn.cursor()
In [ ]:
c.execute("CREATE TABLE npi_data (name TEXT, legal_name TEXT, city TEXT, state TEXT)")
conn.commit()
In [23]:
counter = 0
db_list = []
with open("npidata_20050523-20151108.csv") as infile:
for line in infile:
line = line.replace('"', '')
data = line.split(",")
if (counter > 0):
city = data[22]
state = data[23]
name = data[6] + " " + data[7] + " " + data[5]
legal_name = data[4]
db_list.append( (name, legal_name, city, state) )
#print("Name: " + data[6] + " " + data[7] + " " + data[5])
#print("Legal Name: " + data[4])
# print(data[22], data[23])
#print("\n\n")
#print(line)
#if counter == 5:
# break
counter += 1
print(len(db_list) )
In [25]:
c.executemany("INSERT INTO npi_data VALUES (?, ?, ?, ?)", db_list)
Out[25]:
In [26]:
conn.commit()
conn.close()
In [ ]: